package com.bulemobi.activity.ac_login;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import com.bulemobi.net.tsz.afinal.FinalHttp;
import com.bulemobi.net.tsz.afinal.annotation.view.ViewInject;
import com.bulemobi.net.tsz.afinal.http.AjaxCallBack;
import com.bulemobi.net.tsz.afinal.http.AjaxParams;
import com.bulemobi.urlCentre.UrlCentre;
import com.bulemobi.view.BaseActivity;
import com.bulemobi.view.titleView.ActionBarView;
import com.jsyh.hcb.R;

/**
 * Created by 武 on 2014/9/20 0020.
 * 输入新密码
 *
 */
public class Ac_ForgetPassword_New extends BaseActivity implements View.OnClickListener{
    @ViewInject(id = R.id.tv_confirm)
    TextView tv_confirml;
    @ViewInject(id = R.id.ed_firstPassWord)
    EditText ed_firstPassWord;
    @ViewInject(id = R.id.ed_secondPassWord)
    EditText ed_secondPassWord;
    @ViewInject(id = R.id.actionBar)
    ActionBarView actionBarView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ac_forget_password_new_main);
        initView();
    }
    private void initView(){
        actionBarView.title.setText(getResources().getString(R.string.ac_forget_newPass));
        tv_confirml.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        if(view.getId()==tv_confirml.getId()){
            if(ed_firstPassWord.getText().length()<8){
                showToastShort(getResources().getString(R.string.error_require));
                return;
            }else if(!ed_secondPassWord.getText().toString().equals(ed_firstPassWord.getText().toString())){
                showToastShort(getResources().getString(R.string.error_agian_require));
                return;
            }else{
                tv_confirml.setBackgroundResource(R.drawable.green_shape);
            }
            openActivity(Ac_Login.class);
            finish();
            FinalHttp http = new FinalHttp();
            AjaxParams params = new AjaxParams();
            params.put("TerminalType", UrlCentre.TerminalType);
            params.put("UserType",UrlCentre.UserType);
            params.put("ChannelId",UrlCentre.ChannelId);
            //TODO:这里手机号写死  以后要改
            params.put("Mobile","18049213481");
            params.put("modifyFlag", UrlCentre.modifyFlag);
            params.put("PasswordConfirm",ed_firstPassWord.getText().toString());
            params.put("confirmPassword",ed_secondPassWord.getText().toString());
            http.post(UrlCentre.ResetLoginPwd,params,new AjaxCallBack<Object>() {
                @Override
                public void onStart() {
                    showProgressDialog();
                    super.onStart();
                }

                @Override
                public void onSuccess(Object o) {
                    closeProgressDialog();
                    Log.d("OnSuccess",o.toString());
                    super.onSuccess(o);
                }

                @Override
                public void onFailure(Throwable t, int errorNo, String strMsg) {
                    super.onFailure(t, errorNo, strMsg);
                    closeProgressDialog();
                }
            });
        }
    }
}
